<?php 
if (!defined('BASEPATH')){
	exit('No direct script access allowed');
}

/**
 * SearchCustomers Controller
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class SearchCustomers extends BACKEND_Controller {

	public function __construct() {
		parent::__construct();
		require_once(APPPATH . 'modules/backend/autoload.php');
		if($this->is_logged_in() == FALSE ) {
			$this->session->set_userdata('redirect_uri', current_url());
			redirect('auth');
		}else {
			$this->load->language('stats');
		}
                $this->load->language('searchCustomers');
                $this->load->model('searchCustomers_model');
                
                $this->load->library('bookinglib');
                $this->booking = new bookinglib();
                
	}
        
        private function menuTop(){
            $this->load->model('stats_model');
            $user_info                          = $this->stats_model->get_user_info($this->stats_model->get_user_id());
            $this->view_data['role_by_group']   = $user_info['role_list'];
            $this->view_data['username']        = $user_info['username'];
            return $this->view_data;
        }
        
        private function direct(){
            $checkDirect = $_SERVER['HTTP_REFERER'];
            if(!isset($checkDirect)){
                redirect(base_url());
            }
        }
        
        public function index() {		
		$this->view_data	= array();
		$this->view_data['flash_message_error']         = $this->session->flashdata('flash_message_error');
		$this->view_data['flash_message']		= $this->session->flashdata('flash_message');
		
		if($this->database_connect_status){
                        $this->menuTop();
                        $this->load->view('auth/searchCustomers/search', $this->view_data);
                } else {
                        $this->view_data['flash_message']	= $this->lang->line('database_connect_failed');
                        $this->load->view('templates/backend/error', $this->view_data);	
                }
	}
        
        public function search(){
            if($this->input->server('REQUEST_METHOD')=='POST'){
               $params = array(
                    'name'          =>  $this->input->post('name'),
                    'phone'         =>  $this->input->post('phone')
                );
                
                $this->view_data['info']     =   $this->searchCustomers_model->searchCustomers($params['name'],$params['phone']);
                if(empty($this->view_data['info'])){
                        die("Khong tim thay du lieu KH");
                } else {
                        $this->load->view('auth/searchCustomers/search', $this->view_data);
                        die("");
                }
            }
        }
}